// packagePay/pages/insurance-programme/insurance-programme.js
import user from '../../../utils/user'
import {
    getIntroduceImg
} from '../../api/insurance'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        insureCompanyType: '',
        gscPlan: '',
        wesurePlan: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        getIntroduceImg().then(res => {
            console.log(res, 'res')

            const obj = JSON.parse(res)
            console.log(obj, 'objobj')
            console.log(obj.gscPlan, obj.wesurePlan, 'obj')
            this.setData({
                gscPlan: obj.gscPlan.url,
                wesurePlan: obj.wesurePlan.url
            })
            wx.setNavigationBarColor({
                frontColor: '#ffffff',
                backgroundColor: user.insureCompanyType === 'insure002_gsc' ? obj.gscPlan.colour : obj.wesurePlan.colour
            })
            // 如果未开通日日保 则默认显示 国寿财
            if (user.insureCompanyType === null) {
                wx.setNavigationBarColor({
                    frontColor: '#ffffff',
                    backgroundColor: obj.gscPlan.colour
                })
            }
        })
    },
    onReady() {
        console.log(user, 'user123')
        this.setData({
            insureCompanyType: user.insureCompanyType
        })
    },

    onShow: function () {},
    onPreviewImage(event) {
        const {
            url
        } = event.currentTarget.dataset
        wx.previewImage({
            urls: [url]
        })
    }
})